public class Solution {

        if(head == null){
            return null;
        }
        ListNode prev = head;
        ListNode cur = head.next;
        while(cur!=null){
            if(cur.val==val){
                prev.next=cur.next;
                cur = cur.next;

            }else{
                prev = cur;
                cur = cur.next;

            }
        }
        if(head.val==val){
            head = head.next;
        }
        return head;
    }

}